#pragma once

#include "segment/segment.h"
#include "index/attribute_index/attribute_mem_indexer/multi_value_attribute_mem_indexer.h"
#include "index/attribute_index/attribute_mem_indexer/single_value_attribute_mem_indexer.h"
#include "index/inverted_index/inverted_mem_indexer/inverted_mem_indexer.h"
#include "index/primary_key_index/primary_key_mem_indexer.h"
#include "index/deletion_index/deletion_index_indexer.h"

namespace hawking {
namespace indexlib {

class MemSegment : public Segment {
public:
    MemSegment() : Segment() {
        doc_id_.store(0, std::memory_order_relaxed);
        is_in_dumping_queue_.store(false, std::memory_order_relaxed);
    }
    ~MemSegment() = default;

    virtual bool Dump(const std::string& segment_dir) override;

    bool Init(std::shared_ptr<IndexlibIndexConfig> index_config);

    virtual bool ShouldDump() const override;

    bool AddDocument(std::shared_ptr<NormalDocument> doc) override;

    void ToDumpingQueue() {
        is_in_dumping_queue_.store(true, std::memory_order_acq_rel);
    }

    bool IsInDumpingQueue() const {
        return is_in_dumping_queue_.load(std::memory_order_acq_rel);
    }

private:
    bool Dump_(const std::string& segment_dir);
    std::atomic<DocId> doc_id_;
    std::atomic<bool> is_in_dumping_queue_;
};

}
}